export default {
  jsonp(setting) {
    setting.data = setting.data || {}
    setting.key = setting.key || 'callback'
    setting.callback = setting.callback || function () {}
    setting.data[setting.key] = 'Baidu_callback' //callback="xxxxxx"
    window.Baidu_callback = function (data) {
      // console.log('444', data)
      setting.callback(data)
    }

    var script = document.createElement('script')
    var query_ = []
    for (var key in setting.data) {
      query_.push(key + '=' + encodeURIComponent(setting.data[key]))
    }
    script.src = setting.url + '?' + query_.join('&')
    document.head.appendChild(script)
    document.head.removeChild(script)
  },
}
// 如果路径后不用  callback=‘xxxx’
// jsonp({
//   url: 'http://api.jirengu.com/weather.php',
//   callback: function(ret){
//     console.log(ret)
//   }
// })
// 如果路径后用  callback=‘xxxx’
